#include <iostream>
#include <cstdio>
#include <queue>
using namespace std;
int a[1005][1005],visit[1005][1005];
int n,m;
int direc[4][2] = { {0,1},{0,-1},{1,0},{-1,0} };
struct node {
    int x,y,dir,corner;
};
node start,en;
void BFS() {
    queue<node> q;
    node curr,pre;
    start.dir=-1;
    start.corner=0;
    q.push(start);
    while(!q.empty()) {
        pre=q.front();
        q.pop();
        if (pre.x==en.x && pre.y==en.y) {
            cout<<"YES"<<endl;
            return;
        }
        for (int i=0; i<4; i++) {
            curr.x=pre.x+direc[i][0];
            curr.y=pre.y+direc[i][1];
            curr.corner=pre.corner;
            curr.dir=i;
            if (curr.dir!=pre.dir && pre.dir!=-1) curr.corner++;
            if (curr.x<1 || curr.x>n || curr.y<1 || curr.y>m || curr.corner>2) continue;
            if (a[curr.x][curr.y] && !(curr.x==en.x&&curr.y==en.y)) continue;
            if (curr.corner<visit[curr.x][curr.y]) {
                visit[curr.x][curr.y] = curr.corner;
                q.push(curr);
            }
        }
    }
    cout<<"NO"<<endl;
}
int main() {
    while (cin>>n>>m && n && m) {
        for (int i=1; i<=n; i++)
            for (int j=1; j<=m; j++)
                scanf("%d", &a[i][j]);
        int q;
        cin>>q;
        while(q--) {
            scanf("%d%d%d%d", &start.x, &start.y, &en.x, &en.y);
            if (start.x==en.x && start.y==en.y) {
                cout<<"NO"<<endl;
                continue;
            }
            if (!a[start.x][start.y] || !a[en.x][en.y] || !(a[start.x][start.y]==a[en.x][en.y])) {
                cout<<"NO"<<endl;
                continue;
            }
            for (int i=1 ;i<=n; i++)
                for (int j=1; j<=m; j++)
                    visit[i][j]=5;
            BFS();
        }
    }
    return 0;
}
